Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

promise-retry

Package Overview
Dependencies
Maintainers
2
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

promise-retry

Retries a function that returns a promise, leveraging the power of the retry module.

  • 2.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is promise-retry?

The promise-retry npm package allows users to retry a promise-returning or an async function until it resolves or reaches a maximum number of attempts. It is useful for handling operations that may temporarily fail due to external factors such as network issues or service unavailability.

What are promise-retry's main functionalities?

Basic retry functionality

This feature allows you to retry a promise until it either resolves or fails a specified number of times. The `retry` function is passed to the promise-returning function, and it can be called to retry the operation.

const promiseRetry = require('promise-retry');

function myFunction() {
  return new Promise((resolve, reject) => {
    // An operation that may fail
  });
}

promiseRetry(function (retry, number) {
  console.log('attempt number', number);

  return myFunction().catch(retry);
})
.then(function (value) {
  // resolved value
})
.catch(function (error) {
  // operation failed
});

Custom retry options

This feature allows you to specify custom options for retries, such as the maximum number of attempts, the factor by which the timeout increases, and the minimum and maximum timeout between retries.

const promiseRetry = require('promise-retry');

promiseRetry(function (retry, number) {
  // Your promise-returning function
}, {
  retries: 5, // Maximum number of attempts
  factor: 2, // The exponential factor
  minTimeout: 1 * 1000, // The number of milliseconds before starting the first retry
  maxTimeout: 60 * 1000 // The maximum number of milliseconds between two retries
})
.then(function (value) {
  // resolved value
})
.catch(function (error) {
  // operation failed
});

Other packages similar to promise-retry

Keywords

FAQs

Package last updated on 14 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc